﻿
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Collections;
using Model;


namespace MsDAL
{
    public partial class Ord4a00DAL : Ord4a00Base
    {
        /// <summary>
        /// 审核
        /// </summary>
        public SqlApp Audit(string listid)
        {
            string sql = "UPDATE Ord4a00 SET audstatus = '2' WHERE listid=@listid AND audstatus ='1'";
            SqlParameter[] parameters = {
				new SqlParameter("@listid", SqlDbType.NVarChar)
				};
            parameters[0].Value = listid;

            return new SqlApp(sql, new ArrayList(parameters), false, " 退单审核失败！");
        }

        public SqlApp Back(string listid, double accqty, double amt)
        {
            string sql = string.Format("back_sp '{0}','{1}','{2}' ",
                    listid, accqty, amt);

            return new SqlApp(sql, null, false, "");
        }

        /// <summary>
        /// 更新订单状态为已收货
        /// </summary>
        public SqlApp Receiving(string listid)
        {
            var sql = "UPDATE Ord4a00 SET audstatus = '3', status = '10', instockdate=getdate() "
                + " WHERE listid = @listid AND audstatus IN('2', '3') ";

            SqlParameter[] parameters = {
				new SqlParameter("@listid", SqlDbType.NVarChar)
				};
            parameters[0].Value = listid;

            return new SqlApp(sql, new ArrayList(parameters));
        }

        public SqlApp DoAdjust(string id, double adjQty, double adjAmt)
        {
            var sql = "update ord4a00 set adjtotalqty = isnull(adjtotalqty,0) + @adjtotalqty, adjtotalamt=isnull(adjtotalamt, 0) + @adjtotalamt where listid =@listid";

            SqlParameter[] parameters = {
				new SqlParameter("@adjtotalqty", SqlDbType.Decimal),
				new SqlParameter("@adjtotalamt", SqlDbType.Decimal),
				new SqlParameter("@listid", SqlDbType.NVarChar)
				};
            parameters[0].Value = adjQty;
            parameters[1].Value = adjAmt;
            parameters[2].Value = id;

            return new SqlApp(sql, new ArrayList(parameters), false, "数据保存失败！");
        }
    }
}
